
import AndroidTool from "../module/AndroidTool";
import Log from "./util/Log";
import pfutil from "./util/pfutil";

export default class Plat
{

    public static screenWidth=750;
    public static screenHeight=1334;

    public static userinfo:any=null;


    public static plat_name="cocos";

    public static pt:any={};


    //记录一些微信数据
    public static code:string="";
    public static sessionKey:string="";

    public static isWX():boolean
    {
        return this.plat_name=="wx";
    }


    public static isCocos()
    {
        return this.plat_name=="cocos";
    }

    public static getGameName()
    {
        return this.plat_name+"_hwdfk";  //好玩的方块
    }
    

    public static init()
    {

        Log.warn("平台初始化123");

        let info:any={};
        info.nickName="临时玩家"+pfutil.random(1,1000);
        info.avatarUrl="res/1.png";

        this.userinfo=info;


         if(cc.sys.platform ==cc.sys.WECHAT_GAME)
         {

            Log.warn("微信平台初始化");


            this.plat_name="wx";
            this.pt=wx;

            wx.showShareMenu({
                menus:['shareAppMessage',"shareTimeline"],
              //  withShareTicket:true
            })

            wx.onShareAppMessage(function () {
                return {
                    title: '你能找出八个字吗?',
                    imageUrl: "https://mmocgame.qpic.cn/wechatgame/YyXzjOI0e4ibApMRqsoyJQvMaMsOiadNS8mdxDovz9xPj3odeRiafIyUptxRRycr4uu/0"
                }
              })


              if(wx.onShareTimeline!=null)
              {
                  wx.onShareTimeline(function () {
                    return {
                      title: '你能找出八个字吗?',
                      imageUrl: "https://mmocgame.qpic.cn/wechatgame/YyXzjOI0e4ibApMRqsoyJQvMaMsOiadNS8mdxDovz9xPj3odeRiafIyUptxRRycr4uu/0",
                      imagePreviewUrl:"https://mmocgame.qpic.cn/wechatgame/YyXzjOI0e4ibApMRqsoyJQvMaMsOiadNS8mdxDovz9xPj3odeRiafIyUptxRRycr4uu/0"
                    }
                  })
              }

            
         }


          //注册显示回调
          if(this.pt.onShow!=null)
          {
              this.pt.onShow(this.onshow);
          }


         //屏幕尺寸设置
         if(this.pt.getSystemInfoSync)
         {
           
             let system=this.pt.getSystemInfoSync();

             this.screenWidth=system.screenWidth;
             this.screenHeight=system.screenHeight;
 
             console.warn("屏幕宽:"+system.screenWidth);
             console.warn("屏幕高:"+system.screenHeight);
         }
    }



    private static  fun_obj:any;
    private static  share_obj:any;

    public static setShareCallback(obj:any,fun:any)
    {
        Plat.share_obj=obj;
        Plat.fun_obj=fun;
    }


    public static state=0;
    //显示回调
    public static onshow(res)
    {
        Log.warn("onshow-----")

        Log.error(res)
       

        if(Plat.fun_obj !=null)
        {
            Plat.fun_obj.call(Plat.share_obj);

            Plat.fun_obj=null;
            Plat.share_obj=null;
        }

        if(this.state==0)
        {
         //   AdInterstitial.show();
        }

        this.state=0;
    }

    //显示回调
    public static getLaunchOptionsSync(res)
    {
        Log.warn("getLaunchOptionsSync-----")

        Log.error(res)
       
    }

    public static showToast(str,jg=2000)
    {
        if(this.pt.showToast !=null)
        {
            this.pt.showToast({
                title: str,
                content:str,
                message:str,
                icon: 'none',
                duration: jg
              })
        }      
    }

    public static hideToast()
    {
        if(this.pt.hideToast !=null)
        {
            this.pt.hideToast({
               
              })
        }      
    }

    public static shareAppMessage()
    {
        if(cc.sys.platform==cc.sys.ANDROID){
            AndroidTool.Instance.onShare()
        }

        Plat.state=1;

        if(this.pt.shareAppMessage==null)
        {
            if(Plat.fun_obj !=null)
            {
                Plat.fun_obj.call(Plat.share_obj);
    
                Plat.fun_obj=null;
                Plat.share_obj=null;
            }

            return;
        };

        this.pt.shareAppMessage({
            title: '你能找出八个字吗?',
            imageUrl: "https://mmocgame.qpic.cn/wechatgame/YyXzjOI0e4ibApMRqsoyJQvMaMsOiadNS8mdxDovz9xPj3odeRiafIyUptxRRycr4uu/0",
            // imageUrlId:"N3jjVKcoSbGwfQ5LTudx0w==",
            // templateId:"6c06gh32j4iff897f9",
            desc:"-_-来玩玩吧"
        })
    }

    public static isBigSize()
    {
        if(Plat.screenHeight > Plat.screenWidth * 2)
        {
           return true;
        }  
        
        return false;
    }
}